﻿@model dynamic

@{
    ViewBag.Title = "title";
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="renderer" content="webkit" />
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
    <title>中伟钢物联内部管理系统登录</title>
    <link rel="stylesheet" href="/htm/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="/htm/css/app.css" type="text/css" />
    <link rel="stylesheet" href="/htm/css/less/app.utilities.less" type="text/css" />
</head>
<body>
    <div class="container w-xxl w-auto-xs">
        <a href class="navbar-brand block m-t">中伟钢物联</a>
        <div class="m-b-lg">
            <div class="wrapper text-center">
                <strong>内部管理系统登录</strong>
            </div>
            <form name="form" class="form-validation" onsubmit="return false">
                <div id="error" class="text-danger wrapper text-center"></div>
                <div class="list-group list-group-sm">
                    <div class="list-group-item">
                        <input type="text" placeholder="请输入登录名" class="form-control no-border" required id="username">
                    </div>
                    <div class="list-group-item">
                        <input type="password" placeholder="请输入密码" class="form-control no-border" required id="password">
                    </div>
                </div>
                <input id="salt" value="@ViewBag.salt" type="hidden"/>
                <button type="submit" class="btn btn-lg btn-primary btn-block" onclick="login()">登录</button>
                <div class="line line-dashed"></div>
            </form>
        </div>
        <div class="text-center  m-b-lg">
            <div style="display:inline-block;">
                <label class="navbar-brand">
                    苹果二维码
                </label><br />
                <img src="/htm/img/ios.png" />
            </div>
            <div style="display:inline-block;">
                <label class="navbar-brand">
                    <a href="http://www.zwgwl.com:8060/WGWL.apk">安卓点击下载</a>
                </label><br />
                <img src="/htm/img/android.png" />
            </div>
        </div>
        <div class="text-center">
            <p>
                <small class="text-muted">中伟钢物联发展有限公司 版权所有 <br> 豫ICP备14027827号 <br>增值电信业务经营许可证：豫B2-20150034</small>
            </p>
        </div>
    </div>
</body>
<!-- jQuery -->
<script src="/htm/vendor/jquery/jquery.min.js"></script>
<!--md5-->
<script src="/htm/js/login/md5.js"></script>
<!--loginjs-->
@*<script src="js/login/login.js"></script>*@
</html>

<script>
    if(localStorage.getItem("username")) {
        document.getElementById("username").value= localStorage.getItem("username");
    }
    function login() {
        if (document.getElementById("username").value) {
            localStorage.setItem("username", document.getElementById("username").value);
        }

        var $username = $("#username").val();
        var $password = $("#password").val();
        var $salt = $("#salt").val();
        var md5password = b64_md5($password + $salt);
        if ("" == $username) {
            return false;
        }
        if ("" == $password) {
            return false;
        }
        $.ajax({
            type: "Get",
            url: "/api/Login",
            data: { loginName: $username, md5Pw: md5password, salt: $salt },
            success: function(data) {
                if(data.State <= 0){
                     $("#error").html(data.Msg);
                }else if (data.State > 0){
                    if (typeof (javatojs) != 'undefined') {
                        javatojs.setItem("username" , $username);
                        javatojs.setItem("password" , md5password);
                    }
                    if (typeof (window.webkit) != 'undefined') {
                        window.localStorage.setItem("username",$username)
                        window.localStorage.setItem("password",md5password)
                        window.webkit.messageHandlers.setItem.postMessage({"username":$username , "password":md5password});
                    }
                        window.localStorage.setItem("username",$username)
                        window.localStorage.setItem("password",md5password)

                         sessionStorage.setItem("user",JSON.stringify(data.Data));
                         $("#username").val("");
                         $("#password").val("");
                         function GetQueryString(name){
                               var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                               var r = window.location.search.substr(1).match(reg);
                               if(r!=null)return  unescape(r[2]); return null;
                         }
                         var targetUrl = GetQueryString("url");
                         if (targetUrl == null){
                               location.href = "../../htm/index.html#/app/News/news";
                         }else {
                               location.href = targetUrl;
                         }
                }else{
                     alert("出错了！请重试！");
                     location.reload();
                }
            }
        });
        return false;
    }
</script>